from fastapi import APIRouter

from common.result import Success, Fail

from app.admin.service import UserService
from app.admin.schema.user import UserSchema

router = APIRouter()

@router.delete("/delete/{user_id}", summary="根据ID删除用户")
async def delete_by_user_id(user_id: int):
    await UserService.remove(user_id)
    return Success()

@router.get("/get/{user_id}", summary="获取用户信息")
async def get_by_user_id(user_id: int):
    user = await UserService.get(user_id)
    if not user:
        return Fail(code=404, msg="用户不存在")
    user_dict = await user.to_dict()
    data = UserSchema.model_validate(user_dict).model_dump(exclude=['password'])
    return Success(data=data)